var OrderModel = require('../models').Order;

module.exports = {
    addOrder: addOrder,
    updateOrderStateByOrderId:updateOrderStateByOrderId,
    getAllOrderByCustomerId: getAllOrderByCustomerId,
    getOrderByOrderId: getOrderByOrderId,
    getOrderWithStateByMerchantId: getOrderWithStateByMerchantId
}

function addOrder(order, callback) {
    var orderItem = new OrderModel(order);
    orderItem.save(callback);
}

function updateOrderStateByOrderId(orderId,state ,callback) {
    OrderModel.update({order_id: orderId},{$set:{'state':state}}, callback);
}

function getAllOrderByCustomerId(customer_id, callback) {
    OrderModel.find({customer_id: customer_id}, callback);
}

function getOrderByOrderId(order_id, callback) {
    OrderModel.findOne({order_id: order_id}, callback);
}


function getOrderWithStateByMerchantId(merchant_id,state, callback) {
    OrderModel.find({merchant_id: merchant_id,state:state}, callback);
}

